package org.jeecg.modules.golf.tag.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.golf.tag.entity.Tag;
import org.jeecg.modules.golf.tag.mapper.TagMapper;
import org.jeecg.modules.golf.tag.service.ITagService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 标签
 * @Author: jeecg-boot
 * @Date:   2020-10-18
 * @Version: V1.0
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements ITagService {



    @Override
    public Long findTagIdByTagName(String tagName) {


        Tag tag = new Tag();
        tag.setName(tagName);
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>(tag);
        tag =  getOne(queryWrapper);

        if(tag != null){
            return tag.getId();
        }
        tag  = new Tag();
        tag.setName(tagName);
        save(tag);
        return tag.getId();
    }
}
